package snmp

import (
	"fmt"
	"strconv"
	"strings"
)

// 定义一个结构体来存储厂商信息
type ManufacturerEnum struct {
	ObjectId         int
	ManufacturerName string
}

// 定义模拟枚举的常量
var (
	HUAWEI  = ManufacturerEnum{2011, "HUAWEI Technology Co.,Ltd"}
	H3C     = ManufacturerEnum{25506, "H3C"}
	CISCO   = ManufacturerEnum{9, "Cisco Systems, Inc."}
	LINUX   = ManufacturerEnum{8072, "LINUX"}
	WINDOWS = ManufacturerEnum{311, "WINDOWS"}
)

// 模拟枚举的切片
var manufacturerEnums = []ManufacturerEnum{HUAWEI, H3C, CISCO, LINUX, WINDOWS}

// 查询设备厂商的函数
func manufacturerEstimate(objectOid string) string {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("Recovered from error:", r)
		}
	}()

	idArray := strings.Split(objectOid, ".")
	if len(idArray) < 7 {
		return "未知"
	}

	objectId, err := strconv.Atoi(idArray[7])
	if err != nil {
		return "未知"
	}

	// 遍历模拟的枚举
	for _, manufacturerEnum := range manufacturerEnums {
		if manufacturerEnum.ObjectId == objectId {
			return manufacturerEnum.ManufacturerName
		}
	}

	return "未知"
}
